package com.dragon.modules.yuegou.enums.merchant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * 合作类型
 * 
 * @author pbuilder
 *
 */
public enum MerchantApplyDataCooperationType {

	/**
	 * 常规型
	 */
	CONVENTIONAL(0, "常规型"),
	/**
	 * 战略型
	 */
	STRATEGIC(1, "战略型"),
	/**
	 * 紧密型
	 */
	CLOSELY(2, "紧密型");

	/**
	 * 枚举标识
	 */
	@EnumValue
	@JsonValue
	private final Integer code;

	/**
	 * 别名
	 */
	private final String alias;

	private MerchantApplyDataCooperationType(Integer code, String alias) {
		this.code = code;
		this.alias = alias;
	}
	
	/**
	 * 枚举标识
	 * 
	 * @return code
	 */
	public Integer getCode() {
		return code;
	}

	/**
	 * 别名
	 * 
	 * @return alias
	 */
	public String getAlias() {
		return alias;
	}

	/**
	 * 把code转化为合作类型
	 * 
	 * @param code 代码
	 * @return 合作类型
	 */
	@Nullable
	@JsonCreator
	public static MerchantApplyDataCooperationType from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for MerchantApplyDataCooperationType
	 */
	private static final Map<Integer, MerchantApplyDataCooperationType> CODE_MAP = Stream.of(MerchantApplyDataCooperationType.values())
			.collect(Collectors.toMap(MerchantApplyDataCooperationType::getCode, UnaryOperator.identity()));

}
